import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {DetailProvider} from "../../providers/detail/detail";

@IonicPage()
@Component({
    selector: 'page-detail',
    templateUrl: 'detail.html',
})
export class DetailPage {

    constructor(public navCtrl: NavController, public navParams: NavParams, private detailProvider: DetailProvider) {
    }

    //todo 页面生命周期和数据请求
    ionViewDidLoad() {
        //页面即将加载
        console.log('ionViewDidLoad DetailPage', this.navParams.get('id'));
    }

    ionViewDidEnter() {
        //页面已经加载，后台数据请求一般写这里
        this.detailProvider.getDetails().subscribe(res => {
            console.log(res)
        });
        // this.detailProvider.postDetails().subscribe(res=>{
        //     console.log(res)
        // });
    }

    goAboutDetail() {
        this.navCtrl.push('AboutDetailPage')
    }

    //todo 其他跳转
    //Set the root for the current navigation stack.
    setRoot() {
        // this.navCtrl.setRoot('HomePage');
        this.navCtrl.setRoot('AboutPage');
    }

    goToRoot() {
        this.navCtrl.goToRoot({});
        //  跳转到rootPage  options参数是过度效果的参数,默认没有动画效果
    }

    popToRoot() {
        //退回到rootPage
        this.navCtrl.popToRoot()
    }

    setPages() {
        //设置页面参数
        this.navCtrl.setPages([{page: 'AboutDetailPage', params: {'id': 123}}])
    }
}
